<template>
  <div>
    <div id="head">
      <el-input placeholder="考试名称" v-model="input1" clearable> </el-input>
      <el-button type="primary" icon="el-icon-search">搜索</el-button>
      <el-button>考试时间</el-button>
      <el-date-picker
        v-model="value1"
        type="datetime"
        placeholder="选择开始时间"
      >
      </el-date-picker>
      <el-date-picker
        v-model="value2"
        type="datetime"
        placeholder="选择结束时间"
      >
      </el-date-picker>
      <el-button type="primary" icon="el-icon-search">搜索</el-button>
    </div>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="ID" width="120">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="创建时间" width="120">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column prop="subject" label="学科" width="120">
        <template slot-scope="scope">{{ scope.row.subject }}</template>
      </el-table-column>
      <el-table-column prop="name" label="试卷名称">
        <template slot-scope="scope">{{ scope.row.name }}</template>
      </el-table-column>
      <el-table-column prop="difficulty" label="综合难度" width="120">
        <template slot-scope="scope">{{ scope.row.difficulty }}</template>
      </el-table-column>
      <el-table-column label="操作" width="220">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="success"
            @click="handleView(scope.$index, scope.row)"
            >预览</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="dialogFormVisible">
      <label for="题干："></label>
      <h3>{{ dialogdata.name }}</h3>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data(){
    return {
      input1:'',
      value1:'',
      value2:'',
      dialogFormVisible:false,
      dialogdata:{
        name:''
      },
      tableData:[
        {
          date: "2016-05-03",
          subject: "高等数学",
          id:'001',
          name:'第三次模拟考试',
          difficulty: "3",
        },
        {
          date: "2016-05-03",
          subject: "高等数学",
          id:'002',
          name:'第三次模拟考试',
          difficulty: "3",
        },
        {
          date: "2016-05-03",
          subject: "高等数学",
          id:'003',
          name:'第三次模拟考试',
          difficulty: "3",
        },
      ],
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleView(val,b) {
      console.log(b);
      this.dialogFormVisible=true;
      this.dialogdata.name=b.name;

    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      this.$confirm("将永久删除此试卷, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.tableData = this.filterArr2(this.tableData, row);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    filterArr2(data,row){
      return  data.filter(el => {
        return el.id!=row.id;
      });
    }
  },
};
</script>

<style lang="less" scoped>
.el-input {
  width: 20%;
  margin: 10px;
}
</style>